package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysAllowedJoinCompanyUserDTO;
import com.nineclock.system.dto.SysApplyJoinCompanyUserDTO;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyService;
import com.nineclock.system.service.SysCompanyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@Api(value = "企业管理接口", tags = "系统服务", description = "企业管理接口")
@RequestMapping("company")
public class SysCompanyController {
    @Autowired
    private SysCompanyService sysCompanyService;
    @Autowired
    private SysCompanyUserService sysCompanyUserService;


    @GetMapping("list/{userId}")
    public Result<List<SysCompanyDTO>> queryUserJoinCompany(@PathVariable Long userId){
        return Result.success(sysCompanyService.queryUserJoinCompany(userId));
    }


    @GetMapping
    public Result<SysCompanyDTO> findCompany(){
        SysCompanyDTO sysCompanyDTO = sysCompanyService.findCompany();
        return Result.success(sysCompanyDTO);
    }
    /**
     * 企业管理: 上传图片
     * 接口路径：POST/sys/company/uploadOSS
     * @return
     */
    @PostMapping("uploadOSS")
    @ApiOperation(value = "企业管理: 上传企业的Logo")
    public Result uploadOSS(MultipartFile file) throws Exception{
        String url = sysCompanyService.uploadOSS(file);
        return Result.success(url);
    }

    /**
     * 企业管理: 更新当前企业的基本信息
     * 接口路径：PUT/sys/company
     */
    @PutMapping
    @ApiOperation(value = "企业管理: 更新当前企业的基本信息")
    public Result updateCompany(@RequestBody SysCompanyDTO sysCompanyDTO){
        sysCompanyService.updateCompany(sysCompanyDTO);
        return Result.success();
    }
    /**
     * 企业管理: 获取企业当前主管理员
     * 接口路径：GET/sys/company/getCurrentAdmin
     */

    @GetMapping("getCurrentAdmin")
    @ApiOperation(value = "获取企业当前主管理员")
    public Result<SysCompanyUserDTO> getCurrentAdmin(){
        SysCompanyUserDTO sysCompanyUserDTO = sysCompanyService.getCurrentAdmin();
        return Result.success(sysCompanyUserDTO);
    }
    /**
     * 企业管理: 更改系统管理员
     * 接口路径：POST/sys/company/config/admin
     */
    @PostMapping("config/admin")
    @ApiOperation(value = "企业管理: 更改系统管理员")
    public Result changeAdmin(@RequestBody Map<String,Object> map){
        sysCompanyService.changeAdmin(map);
        return Result.success();
    }
    /**
     *根据关键字名称查询企业
     * 接口路径：GET/sys/company/list
     */
    @ApiOperation("根据关键字名称查询企业")
    @GetMapping("list")
    public Result<List<SysCompanyDTO>> listCompany(String keyword){
        List<SysCompanyDTO> sysCompanyDTOList = sysCompanyService.listCompany(keyword);
        return Result.success(sysCompanyDTOList);
    }
    /**
     * 加入企业申请
     * 接口路径：POST/sys/company/applyJoinCompany
     */
    @ApiOperation("加入企业申请")
    @PostMapping("applyJoinCompany")
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO sysApplyJoinCompanyUserDTO){
        sysCompanyService.applyJoinCompany(sysApplyJoinCompanyUserDTO);
        return Result.success();
    }
    /**
     * 加入企业审核
     * 接口路径：POST/sys/company/allowedJoinCompany
     */
    @ApiOperation("加入企业审核")
    @PostMapping("allowedJoinCompany")
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO allowedJoinCompanyUserDTO){
        sysCompanyService.allowedJoinCompany(allowedJoinCompanyUserDTO);
        return Result.success();
    }

}
